package com.yhd.controller;

import com.yhd.entity.TCourse;
import com.yhd.entity.TCycleImg;
import com.yhd.entity.dto.CourseDto;
import com.yhd.entity.dto.CycleImgDto;
import com.yhd.entity.result.ResultVo;
import com.yhd.model.ResultPage;
import com.yhd.service.CourseService;
import com.yhd.service.CycleImgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@Api(value = "小程序首页")
@Slf4j
@RequestMapping(value = "/app/index")
@CrossOrigin
public class AppIndexController extends WebBaseController {

    @Autowired
    private CycleImgService cycleImgService;
    @Autowired
    private CourseService courseService;
    
    
    @ApiOperation(value = "课程轮播图", httpMethod = "GET", notes = "")
    @ApiImplicitParams({@ApiImplicitParam(name = "type", value = "类型 activity:活动，course:课程", required = true, paramType = "字符串")})
    @GetMapping("/cycleList")
    @ResponseBody
    public ResultVo<List<CycleImgDto>> cycleList(String type) {
        List<CycleImgDto> result = cycleImgService.getCycleList(type);
        return ResultVo.success(result);
    }
    
    @ApiOperation(value = "课程列表", httpMethod = "GET", notes = "")
    @ApiImplicitParams({@ApiImplicitParam(name = "pageNum", value = "页码", required = true, paramType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示数量", required = true, paramType = "int")})
    @GetMapping("/courseList")
    @ResponseBody
    public ResultVo<ResultPage<List<CourseDto>>> courseList(Integer pageNum, Integer pageSize) {
        ResultPage<List<CourseDto>> result = courseService.getCourseList("course", pageNum, pageSize);
        return ResultVo.success(result);
    }
    
    

}
